<div class="tableinfo">
    <div class="tableHeader">
        <p>kết quả tìm kiếm</p>
    </div>
    
    
    <table border ="0" cellspacing ="0" cellpadding ="0">

        
        <?php 
    $yeucau=$_POST['truonghop'];  
    if($_SESSION['vaitro']=="Quản Trị"){
          if($yeucau=="timdean"){
            $madean=$_POST['madeans'];
            $tendean=$_POST['tendeans'];
            $diadiem=$_POST['diadiemdean'];
            $search=$_POST['search'];
            
            //xet dau "," trong cau lenh SQL
            if((isset($madean)&&isset($tendean)&&!isset($diadiem))||(isset($madean)&&isset($tendean)&&isset($diadiem))||(isset($madean)&&!isset($tendean)&&isset($diadiem))){
               $dau1=",";
               $or1="or"; 
            }else{
               $dau1="";
               $or1=""; 
            }
            
            if((isset($madean)&&isset($tendean)&&isset($diadiem))||(!isset($madean)&&isset($tendean)&&isset($diadiem))){
               $dau2=",";
               $or2="or"; 
            }else{
               $dau2="";
               $or2=""; 
            }
            
            if(isset($madean)){
                $dk1 = "$madean like '%$search%'";
            }else{
                $dk1="";
            }
            
            if(isset($tendean)){
                $dk2 = "$tendean like '%$search%'";
            }else{
                $dk2="";
            }
            
            if(isset($diadiem)){
                $dk3 = "$diadiem like '%$search%'";
            }else{
                $dk3="";
            }                        
            

            //liệt ke kết quả
            $sql_search="select $madean$dau1$tendean$dau2$diadiem from dean where $dk1 $or1 $dk2 $or2 $dk3 ";
            //echo $sql_search;
            $timkiem = executeQuery($sql_search);
            echo "<tr style='background: silver; font-weight: bold;'><td>Mã Đề Án </td><td>Tên Đề Án</td><td >Địa Điểm</td></tr>";
            while($row_tim = mysql_fetch_array($timkiem)){
               echo "<tr><td>".$row_tim['MaDA']."</td><td>".$row_tim['TenDA']."</td><td>".$row_tim['DDiemDA']."</td></tr>"; 
            }
            
            
            
          }elseif($yeucau=="timphongban"){
            
            $maphong=$_POST['maphongs'];
            $tenphong=$_POST['tenphong'];
            $maTP=$_POST['matp'];
            $search=$_POST['search'];
            
            //xet dau "," trong cau lenh SQL
            if((isset($maphong)&&isset($tenphong)&&!isset($maTP))||(isset($maphong)&&isset($tenphong)&&isset($maTP))||(isset($maphong)&&!isset($tenphong)&&isset($maTP))){
               $dau1=",";
               $or1="or"; 
            }else{
               $dau1="";
               $or1=""; 
            }
            
            if((isset($maphong)&&isset($tenphong)&&isset($maTP))||(!isset($maphong)&&isset($tenphong)&&isset($maTP))){
               $dau2=",";
               $or2="or"; 
            }else{
               $dau2="";
               $or2=""; 
            }
            
            if(isset($maphong)){
                $dk1 = "$maphong like '%$search%'";
            }else{
                $dk1="";
            }
            
            if(isset($tenphong)){
                $dk2 = "$tenphong like '%$search%'";
            }else{
                $dk2="";
            }
            
            if(isset($maTP)){
                $dk3 = "$maTP like '%$search%'";
            }else{
                $dk3="";
            }                        
            

            //liệt ke kết quả
            $sql_search="select $maphong$dau1$tenphong$dau2$maTP from phongban where $dk1 $or1 $dk2 $or2 $dk3 ";
            //echo $sql_search;
            $timkiem = executeQuery($sql_search);
            echo "<tr style='background: silver; font-weight: bold;'><td>Mã Phòng </td><td>Tên Phòng</td><td >Trưởng Phòng</td></tr>";
            while($row_tim = mysql_fetch_array($timkiem)){
               echo "<tr><td>".$row_tim['MaPhong']."</td><td>".$row_tim['TenPhong']."</td><td>".$row_tim['MaTRGP']."</td></tr>"; 
            }
            
          }elseif($yeucau=="timnhanvien"){
            $manv = $_POST['manhanvien'];
            $hoten = $_POST['hoten'];
            $diachi = $_POST['diachi'];
            $dt = $_POST['dienthoai'];
            $vaitro = $_POST['vaitro'];
            $phongban = $_POST['phongban'];
            $search=$_POST['search'];
            
            if(isset($manv)&& (isset($hoten)||isset($diachi)||isset($dt)||isset($vaitro)||isset($phongban))){
                $dau1=",";
                $or1="or";   
            }else{
                $dau1="";
                $or1="";                  
            }
            
            if(isset($hoten)&&(isset($diachi)||isset($dt)||isset($vaitro)||isset($phongban))){
                $dau2=",";
                $or2="or";
            }else{
                $dau2="";
                $or2="";
            }
            
            if(isset($diachi)&&(isset($dt)||isset($vaitro)||isset($phongban))){
                $dau3=",";
                $or3="or";
            }else{
                $dau3="";
                $or3="";
            }
            
            if(isset($dt)&&(isset($vaitro)||isset($phongban))){
                $dau4=",";
                $or4="or";
                
            }else{
                $dau4="";
                $or4="";
            }
            
            if(isset($vaitro)&&isset($phongban)){
                $dau5=",";
                $or5="or";
            }else{
                $dau5="";
                $or5="";
            }
            
            if(isset($manv)){
                $dk1 = "$manv like '%$search%'";
            }else{
                $dk1 ="";
            }
            
            if(isset($hoten)){
                $dk2 = "$hoten like '%$search%'";
            }else{
                $dk2 ="";
            }
            if(isset($diachi)){
                $dk3 = "$diachi like '%$search%'";
            }else{
                $dk3 ="";
            }
            if(isset($dt)){
                $dk4 = "$dt like '%$search%'";
            }else{
                $dk4 ="";
            }
                                                           
            $sql_search="select *  from chitietnhanvien where $dk1 $or1 $dk2 $or2 $dk3 $or3 $dk4";
            //echo $sql_search;
                $timkiem = executeQuery($sql_search);
                echo "<tr style='background: silver; font-weight: bold;'><td>Mã NV </td><td>Họ Tên</td><td >Giới tính</td><td >Điện thoại</td><td >Địa chỉ</td><td >Email</td></tr>";
                while($row_tim = mysql_fetch_array($timkiem)){
                echo "<tr><td>".$row_tim['id_NhanVien']."</td><td>".$row_tim['HoTen']."</td><td>".$row_tim['GioiTinh']."</td><td>".$row_tim['DienThoai']."</td><td>".$row_tim['DiaChi']."</td><td>".$row_tim['Email']."</td></tr>"; 
            }
          }elseif($yeucau=="timtinnhan"){
            $user= $_SESSION['userlogin'];
            $tieudetn=$_POST['tdtinnhan'];
            $noidungtn=$_POST['ndtinnhan'];
            $search=$_POST['search'];
            
            //xet dau "," trong cau lenh SQL
            if(isset($tieudetn) && isset($noidungtn)){
               $dau1=",";
               $or1="or"; 
            }else{
               $dau1="";
               $or1=""; 
            }
            
           
            if(isset($tieudetn)){
                $dk1 = "$tieudetn like '%$search%'";
            }else{
                $dk1="";
            }
            
            if(isset($noidungtn)){
                $dk2 = "$noidungtn like '%$search%'";
            }else{
                $dk2="";
            }

            //liệt ke kết quả
            $sql_search="select $tieudetn $dau1 $noidungtn, id_NhanVien, NhanVienNhan from tinnhangui where ($dk1 $or1 $dk2) and (id_NhanVien= $user or NhanVienNhan = $user)";
            //echo $sql_search;
            $timkiem = executeQuery($sql_search);
            echo "<tr style='background: silver; font-weight: bold;'><td>Tiêu đề</td><td>Nội dung</td><td >Người gởi</td><td >Người nhận</td></tr>";
            while($row_tim = mysql_fetch_array($timkiem)){
               echo "<tr><td>".$row_tim['TieuDe']."</td><td>".$row_tim['NoiDung']."</td><td>".$row_tim['id_NhanVien']."</td><td>".$row_tim['NhanVienNhan']."</td></tr>"; 
            }            
            
          }elseif($yeucau=="timthongbao"){
            $tieudetb=$_POST['tdthongbao'];
            $noidungtb=$_POST['ndthongbao'];
            $search=$_POST['search'];
            
            //xet dau "," trong cau lenh SQL
            if(isset($tieudetb) && isset($noidungtb)){
               $dau1=",";
               $or1="or"; 
            }else{
               $dau1="";
               $or1=""; 
            }
            
           
            if(isset($tieudetb)){
                $dk1 = "$tieudetb like '%$search%'";
            }else{
                $dk1="";
            }
            
            if(isset($noidungtb)){
                $dk2 = "$noidungtb like '%$search%'";
            }else{
                $dk2="";
            }

            //liệt ke kết quả
            $sql_search="select $tieudetb $dau1 $noidungtb,NgayDang from thongbao where $dk1 $or1 $dk2 ";
            //echo $sql_search;
            $timkiem = executeQuery($sql_search);
            echo "<tr style='background: silver; font-weight: bold;'><td>Tiêu đề</td><td>Nội dung</td><td >Ngày đăng</td></tr>";
            while($row_tim = mysql_fetch_array($timkiem)){
               echo "<tr><td>".$row_tim['TieuDe']."</td><td>".$row_tim['NoiDung']."</td><td>".$row_tim['NgayDang']."</td></tr>"; 
            }            
          }         
    }else{
        //khu vuc danh cho user
        if($yeucau=="timphongban"){
            
            $maphong=$_POST['maphongs'];
            $tenphong=$_POST['tenphong'];
            $maTP=$_POST['matp'];
            $search=$_POST['search'];
            
            //xet dau "," trong cau lenh SQL
            if((isset($maphong)&&isset($tenphong)&&!isset($maTP))||(isset($maphong)&&isset($tenphong)&&isset($maTP))||(isset($maphong)&&!isset($tenphong)&&isset($maTP))){
               $dau1=",";
               $or1="or"; 
            }else{
               $dau1="";
               $or1=""; 
            }
            
            if((isset($maphong)&&isset($tenphong)&&isset($maTP))||(!isset($maphong)&&isset($tenphong)&&isset($maTP))){
               $dau2=",";
               $or2="or"; 
            }else{
               $dau2="";
               $or2=""; 
            }
            
            if(isset($maphong)){
                $dk1 = "$maphong like '%$search%'";
            }else{
                $dk1="";
            }
            
            if(isset($tenphong)){
                $dk2 = "$tenphong like '%$search%'";
            }else{
                $dk2="";
            }
            
            if(isset($maTP)){
                $dk3 = "$maTP like '%$search%'";
            }else{
                $dk3="";
            }                        
            

            //liệt ke kết quả
            $sql_search="select $maphong$dau1$tenphong$dau2$maTP from phongban where $dk1 $or1 $dk2 $or2 $dk3 ";
            //echo $sql_search;
            $timkiem = executeQuery($sql_search);
            echo "<tr style='background: silver; font-weight: bold;'><td>Mã Phòng </td><td>Tên Phòng</td><td >Trưởng Phòng</td></tr>";
            while($row_tim = mysql_fetch_array($timkiem)){
               echo "<tr><td>".$row_tim['MaPhong']."</td><td>".$row_tim['TenPhong']."</td><td>".$row_tim['MaTRGP']."</td></tr>"; 
            }
        }elseif($yeucau=="timtinnhan"){
            $user= $_SESSION['userlogin'];
            $tieudetn=$_POST['tdtinnhan'];
            $noidungtn=$_POST['ndtinnhan'];
            $search=$_POST['search'];
            
            //xet dau "," trong cau lenh SQL
            if(isset($tieudetn) && isset($noidungtn)){
               $dau1=",";
               $or1="or"; 
            }else{
               $dau1="";
               $or1=""; 
            }
            
           
            if(isset($tieudetn)){
                $dk1 = "$tieudetn like '%$search%'";
            }else{
                $dk1="";
            }
            
            if(isset($noidungtn)){
                $dk2 = "$noidungtn like '%$search%'";
            }else{
                $dk2="";
            }

            //liệt ke kết quả
            $sql_search="select $tieudetn $dau1 $noidungtn, id_NhanVien, NhanVienNhan from tinnhangui where ($dk1 $or1 $dk2) and (id_NhanVien= $user or NhanVienNhan = $user)";
            //echo $sql_search;
            $timkiem = executeQuery($sql_search);
            echo "<tr style='background: silver; font-weight: bold;'><td>Tiêu đề</td><td>Nội dung</td><td >Người gởi</td><td >Người nhận</td></tr>";
            while($row_tim = mysql_fetch_array($timkiem)){
               echo "<tr><td>".$row_tim['TieuDe']."</td><td>".$row_tim['NoiDung']."</td><td>".$row_tim['id_NhanVien']."</td><td>".$row_tim['NhanVienNhan']."</td></tr>"; 
            }            
            
          }elseif($yeucau=="timthongbao"){
            $tieudetb=$_POST['tdthongbao'];
            $noidungtb=$_POST['ndthongbao'];
            $search=$_POST['search'];
            
            //xet dau "," trong cau lenh SQL
            if(isset($tieudetb) && isset($noidungtb)){
               $dau1=",";
               $or1="or"; 
            }else{
               $dau1="";
               $or1=""; 
            }
            
           
            if(isset($tieudetb)){
                $dk1 = "$tieudetb like '%$search%'";
            }else{
                $dk1="";
            }
            
            if(isset($noidungtb)){
                $dk2 = "$noidungtb like '%$search%'";
            }else{
                $dk2="";
            }

            //liệt ke kết quả
            $sql_search="select $tieudetb $dau1 $noidungtb,NgayDang from thongbao where $dk1 $or1 $dk2 ";
            //echo $sql_search;
            $timkiem = executeQuery($sql_search);
            echo "<tr style='background: silver; font-weight: bold;'><td>Tiêu đề</td><td>Nội dung</td><td >Ngày đăng</td></tr>";
            while($row_tim = mysql_fetch_array($timkiem)){
               echo "<tr><td>".$row_tim['TieuDe']."</td><td>".$row_tim['NoiDung']."</td><td>".$row_tim['NgayDang']."</td></tr>"; 
            }            
          }elseif($yeucau=="timdean"){
            $idnv = $_SESSION['userlogin'];
            $madean= $_POST['madeans'];
            $tendean=$_POST['tendeans'];
            $diadiem=$_POST['diadiemdean'];
            $search=$_POST['search'];
            
            //xet bien $a
            if(isset($madean)){
              $a ="a." ; 
            }else{
                $a="";
            }
            if(isset($tendean)){
              $b ="a." ; 
            }else{
                $b="";
            }
            if(isset($diadiem)){
              $c ="a." ; 
            }else{
                $c="";
            }
            
            //xet dau "," trong cau lenh SQL
            if((isset($madean)&&isset($tendean)&&!isset($diadiem))||(isset($madean)&&isset($tendean)&&isset($diadiem))||(isset($madean)&&!isset($tendean)&&isset($diadiem))){
               $dau1=",";
               $or1="or"; 
            }else{
               $dau1="";
               $or1=""; 
            }
            
            if((isset($madean)&&isset($tendean)&&isset($diadiem))||(!isset($madean)&&isset($tendean)&&isset($diadiem))){
               $dau2=",";
               $or2="or"; 
            }else{
               $dau2="";
               $or2=""; 
            }
            
            if(isset($madean)){
                $dk1 = "$madean like '%$search%'";
            }else{
                $dk1="";
            }
            
            if(isset($tendean)){
                $dk2 = "$tendean like '%$search%'";
            }else{
                $dk2="";
            }
            
            if(isset($diadiem)){
                $dk3 = "$diadiem like '%$search%'";
            }else{
                $dk3="";
            }                        
            

            //liệt ke kết quả
            $sql_search="select $a $madean $dau1 $b $tendean $dau2 $c $diadiem from dean a 
                            inner join phancong b on a.MaDA = b.MaDA 
                            where ($a $dk1 $or1 $b $dk2 $or2 $c $dk3) and b.id_NhanVien='$idnv' ";
            
            
            //echo $sql_search;
            $timkiem = executeQuery($sql_search);
            echo "<tr style='background: silver; font-weight: bold;'><td>Mã Đề Án </td><td>Tên Đề Án</td><td >Địa Điểm</td></tr>";
            while($row_tim = mysql_fetch_array($timkiem)){
               echo "<tr><td>".$row_tim['MaDA']."</td><td>".$row_tim['TenDA']."</td><td>".$row_tim['DDiemDA']."</td></tr>"; 
            }
            
            
            
          }
    }          


            
        ?>
    </table>

     
</div>
